package com.cyz.admin.controller;

import com.cyz.common.dto.UserDto;
import com.cyz.admin.service.Admin_UserService;
import com.cyz.common.utils.R;
import com.cyz.common.validated.AddGroup;
import com.cyz.common.validated.UpdateGroup;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Api(tags = "管理端用户相关接口")
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private Admin_UserService adminAdminUserService;

    @ApiOperation(value = "管理员登录")
    @PostMapping("/login")
    public R login(@Validated(AddGroup.class) @RequestBody UserDto userDto) {
        return adminAdminUserService.login(userDto);
    }

    @ApiOperation(value = "查询登录人各种信息")
    @GetMapping("/getInfo")
    public R getInfo() {
        return adminAdminUserService.getInfo();
    }

    @ApiOperation(value = "查询登录人能够浏览的路由菜单")
    @GetMapping("/getRouters")
    public R getRouters() {
        return adminAdminUserService.getRouters();
    }

    @ApiOperation(value = "退出系统")
    @GetMapping("/logout")
    public R logout() {
        return adminAdminUserService.logout();
    }

    @ApiOperation(value = "更新登录人信息")
    @PutMapping("/updateMsg")
    public R updateMsg(@Validated(UpdateGroup.class) @RequestBody UserDto userDto) {
        return adminAdminUserService.updateMsg(userDto);
    }
}
